package controllers

import (
       "fs_oms/models"
	"github.com/astaxie/beego"
)

type AddGatewayController struct {
	beego.Controller
}

func (c *AddGatewayController) Get() {
	c.TplName = "addgateway.tpl"
}

func (c *AddGatewayController) Post() {
	var name = c.GetString("name")
	var accountcode = c.GetString("accountcode")
	var password = c.GetString("password")
	var realm = c.GetString("realm")

	if models.IsGatewayExist(accountcode) {
		c.Data["result"] = "网关" + accountcode + "已经存在!"
	} else {
		err := models.AddGateway(name, accountcode, password, realm)
		if err != nil {
			c.Data["result"] = "增加网关" + name + "失败!"
			c.Data["reason"] = err.Error()
		} else {
			models.SyncData()
			c.Data["result"] = "增加网关" + name + "成功!"
		}
	}

	c.TplName = "addgateway_result.tpl"
}
